home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / sbin / resolvconf < prev    next >
Encoding:
Text File  |  2006-08-09  |  2.3 KB  |  97 lines

  1. #!/bin/bash
  2. # Need bash because of use of ${FOO/bar}
  3. #
  4. # Licensed under the GNU GPL.  See /usr/share/doc/resolvconf/copyright.
  5. #
  6. # History
  7. # Jun 2003 - April 2005: Written by Thomas Hood <jdthood@yahoo.co.uk>
  8. #
  9. # resolvconf (-u|-d IFACE|-a IFACE)
  10.  
  11. set -e
  12.  
  13. echo_usage() { echo "Usage: resolvconf (-u|-d IFACE|-a IFACE)" ; }
  14.  
  15. PATH=/sbin:/bin
  16. MYNAME="${0##*/}"
  17. # Note that /etc/resolvconf/run may be a symlink
  18. RUN_DIR=/etc/resolvconf/run
  19. IFACE_DIR="${RUN_DIR}/interface"
  20. ENABLE_UPDATES_FLAGFILE="${RUN_DIR}/enable-updates"
  21.  
  22. report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
  23.  
  24. # Check arguments
  25. CMD="$1"
  26. case "$CMD" in
  27.   -u)
  28.       if [ "$2" ] ; then
  29.         report_err "The -u option does not take an argument"
  30.         echo_usage >&2
  31.         exit 1
  32.     fi
  33.     ;;
  34.   -a|-d)
  35.     IFACE="$2"
  36.     if [ -z "$IFACE" ] ; then
  37.         report_err "No interface name specified"
  38.         echo_usage >&2
  39.         exit 1
  40.     fi
  41.     report_iface_err() {
  42.         report_err "$* not allowed in interface record name"
  43.     }
  44.     [ "${IFACE/\/}" = "$IFACE" ] || { report_iface_err "Slash" ; exit 1 ; }
  45.     [ "${IFACE/ }" = "$IFACE" ] || { report_iface_err "Space" ; exit 1 ; }
  46.     [ "${IFACE#.}" = "$IFACE" ] || { report_iface_err "Initial dot" ; exit 1 ; }
  47.     [ "${IFACE#-}" = "$IFACE" ] || { report_iface_err "Initial hyphen" ; exit 1 ; }
  48.     [ "${IFACE#\~}" = "$IFACE" ] || { report_iface_err "Initial tilde" ; exit 1 ; }
  49.     ;;
  50.   *)
  51.     report_err "Invalid argument"
  52.     echo_usage >&2
  53.     exit 1
  54.     ;;
  55. esac
  56.  
  57. [ -d "$IFACE_DIR" ] || { report_err "$IFACE_DIR is not a directory" ; exit 1 ; }
  58.  
  59. cd "$IFACE_DIR"
  60.  
  61. case "$CMD" in
  62.   -u) : ;;
  63.   -a)
  64.     OLD_CONTENT=""
  65.     [ -f "$IFACE" ] && OLD_CONTENT="$(cat "$IFACE")"
  66.     NEW_CONTENT="$(sed 's/#.*//' -)"
  67.     # Proceed only if content has changed. The test here can't
  68.     # eliminate 100% of redundant invocations of update scripts
  69.     # because we don't do any locking; however it certainly does
  70.     # eliminate most of them.
  71.     if [ "$NEW_CONTENT" = "$OLD_CONTENT" ] ; then 
  72.         exit 0
  73.     fi
  74.     IFACE_TMPFILE="${IFACE}_new.$$"
  75.     cleanup() { rm -f "$IFACE_TMPFILE" ; }
  76.     trap cleanup EXIT
  77.     echo "$NEW_CONTENT" > "$IFACE_TMPFILE"
  78.     mv -f "$IFACE_TMPFILE" "$IFACE"
  79.     ;;
  80.   -d)
  81.     if [ ! -s "$IFACE" ] ; then
  82.         rm -f "$IFACE"
  83.         exit 0
  84.     fi
  85.     rm -f "$IFACE"
  86.     ;;
  87.   *)
  88.     report_err "Command not recognized"
  89.     exit 99
  90.     ;;
  91. esac
  92.  
  93. [ -e "$ENABLE_UPDATES_FLAGFILE" ] || exit 0
  94.  
  95. exec run-parts "--arg=$CMD" ${IFACE:+--arg="$IFACE"} /etc/resolvconf/update.d
  96.  
  97.